﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Highcharts;
using log4net;
using StockPredictor.App_Start;
using StockPredictor.Models;
using StockPredictor.Utilities;

namespace StockPredictor.Controllers
{
    
    public class HomeController : Controller
    {
        private readonly ILog logger = LogManager.GetLogger(typeof(HomeController));

        #region View Commands
        public ActionResult Index()
        {            
            // Initialize the site
            this.Initialize();
            ViewBag.Message = "Your index page.";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }
        #endregion View Commands

        #region Initialization

        private void Initialize()
        {
            // configure the logger
            log4net.Config.XmlConfigurator.Configure();
        }

        public JsonResult ChartResults(string stockSymbol)
        {
            var results = StockChartHelper.GetChartResults(stockSymbol);
            var jsonResult = Json(results.Select(x => new[] { x.x, x.open, x.high, x.low, x.close}));
            jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return jsonResult;
        }

        #endregion Initialization
    }
}
